<template>
  <div class="ProductOne">
    <h1>ProductOne</h1>
    <ul>
      <li v-for="product in saleProduts" :key="product.id" > 
        {{product.name}}----{{product.price}}----{{product.id}}
      </li>
    </ul>
    <button @click="reducePrice(10)">商品降价</button>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    products() {
      return this.$store.state.products;
    },
    // saleProduts() {
    //   return this.$store.getters.saleProduts;
    // }
    ...mapGetters(["saleProduts"])
  },
  methods: {
    // reducePrice(num) {
    //   // this.$store.state.products.map(product => {
    //   //   product.price -= 1;
    //   // });
    //   // this.$store.commit("reducePrice");
    //   this.$store.dispatch("reducePrice", num);
    // }
    ...mapActions(["reducePrice"])
  }
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
